import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: "/",
    redirect: "/Home"
  },
  {
    path: '/Home',
    name: "Home",
    component: Home,
    redirect: "/commodity",
    children:[
      {
        path:"/commodity",
        name:"commodity",
        component: () => import("../views/basics/commodity"),
        meta:{
          father:"基础管理",
          son:"商品管理"
        }
      },
      {
        path:"/order",
        name:"order",
        component: ()=>import('../views/order/order'),
        meta: {
          father: "订单管理",
          son: "交易订单"
        }
      },
      {
        path: "/one",
        name: "one",
        component: () => import('../views/system/one'),
        meta: {
          father: "系统管理",
          son: "用户管理"
        }
      },
      {
        path: "/two",
        name: "two",
        component: () => import('../views/system/two'),
        meta: {
          father: "系统管理",
          son: "菜单管理"
        }
      },
      {
        path: "/three",
        name: "three",
        component: () => import('../views/system/three'),
        meta: {
          father: "系统管理",
          son: "角色管理"
        }
      },
      {
        path: "/four",
        name: "four",
        component: () => import('../views/system/four'),
        meta: {
          father: "系统管理",
          son: "公司管理"
        }
      },
      {
        path: "/five",
        name: "five",
        component: () => import('../views/system/five'),
        meta: {
          father: "系统管理",
          son: "系统环境变量"
        }
      },
      {
        path: "/six",
        name: "six",
        component: () => import('../views/system/six'),
        meta: {
          father: "系统管理",
          son: "权限管理"
        }
      },
      {
        path: "/seven",
        name: "seven",
        component: () => import('../views/transaction/one'),
        meta: {
          father: "支付管理",
          son: "支付配置信息"
        }
      },
      {
        path: "/eight",
        name: "eight",
        component: () => import('../views/transaction/two'),
        meta: {
          father: "支付管理",
          son: "支付配置"
        }
      },
    ]
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/login.vue"),
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (localStorage.getItem('token')) {
    next();
  } else {
    if (to.path == "/login") {
      next()
    } else {
      next("/login")
    }
  }
})




export default router
